package com.k.base.jdk.functions.demo4;

import java.util.function.Consumer;

public class PersonOne {
    private Heart heart;
    private Gan  gan;
    private Fei fei;

    private PersonOne(){
        heart = new Heart();
        gan = new Gan();
        fei = new Fei();
    }

    // public 才可以使用 lambda传值
    // GenOne.create()
    // .setHeart(a->{a.setHeartCode("heart001");})
    // static 才可以被外部创建 如：GenOne.Heart heart = new GenOne.Heart()
    public static class Heart{
        private String heartCode;

        public Heart() {
        }

        public Heart(String heartCode) {
            this.heartCode = heartCode;
        }

        public String getHeartCode() {
            return heartCode;
        }

        public void setHeartCode(String heartCode) {
            this.heartCode = heartCode;
        }

        @Override
        public String toString() {
            return "Heart{" +
                    "heartCode='" + heartCode + '\'' +
                    '}';
        }
    }
    public static class Gan{
        private String ganCode;

        public Gan() {
        }

        public Gan(String ganCode) {
            this.ganCode = ganCode;
        }

        public String getGanCode() {
            return ganCode;
        }

        public void setGanCode(String ganCode) {
            this.ganCode = ganCode;
        }

        @Override
        public String toString() {
            return "Gan{" +
                    "ganCode='" + ganCode + '\'' +
                    '}';
        }
    }
    public static class Fei{
        private String feiCode;

        public Fei(String feiCode) {
            this.feiCode = feiCode;
        }

        public Fei() {
        }

        public String getFeiCode() {
            return feiCode;
        }
        public void setFeiCode(String feiCode) {
            this.feiCode = feiCode;
        }

        @Override
        public String toString() {
            return "Fei{" +
                    "feiCode='" + feiCode + '\'' +
                    '}';
        }
    }


    /**
     * 外部使用 lambada 赋值
     * @param c c
     * @return this
     */
    public PersonOne setHeart(Consumer<Heart> c) {
        c.accept(this.heart);
        return this;
    }
    public PersonOne setHeart(Heart heart){
        this.heart = heart;
        return this;
    }

    public PersonOne setGan(Consumer<Gan> c) {
        c.accept(this.gan);
        return this;
    }
    public PersonOne setGan(Gan gan){
        this.gan = gan;
        return this;
    }

    public PersonOne setFei(Consumer<Fei> c) {
        c.accept(this.fei);
        return this;
    }
    public PersonOne setFei(Fei fei){
        this.fei = fei;
        return this;
    }

    public static PersonOne create(){
        return new PersonOne();
    }

    public void isPerson(){
        String myHeartCode = this.heart.getHeartCode();
        String myGanCode = this.gan.getGanCode();
        String myFeiCode = this.fei.getFeiCode();
        System.out.println("heart:"+myHeartCode+" gan:"+myGanCode+" fei:"+myFeiCode);
        if(myHeartCode!=null && myGanCode!=null && myFeiCode!=null){
            System.out.println("this is a person");
        }else{
            System.out.println("this is not person");
        }
    }
}
